package com.delu.controoler;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.RoundImg;
import com.delu.entity.Site;
import com.delu.entity.SiteCar;
import com.delu.mapper.SiteCarMapper;
import com.delu.mapper.SiteMapper;
import com.delu.service.IRoundImgService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("roundhitch")
@ResponseBody
public class RoundImgHitchController {
    @Autowired
    private IRoundImgService iRoundImgService;
    @Autowired
    private SiteCarMapper siteCarMapper;

    @Autowired
    private RestTemplate restTemplate;
    //轮播图展示
    @GetMapping("select")
    public Result SelectRoundImg(){
        //根据前台传来的id,获取所对应的轮播图图片
        List<RoundImg> list =   iRoundImgService.SelectRoundImg();

        return Result.response(ResultEnum.SUCCESS).setData(list);
    }
    //通过地图接口获取用户所在城市,将此城市顺风车推送
    //顺风车推荐
    //通过地图接口获取用户所在城市,将此城市顺风车推荐
    @GetMapping("map")
    public Result HitchRideRecommend(){
        //通过地图接口获取城市定位
        String ak = "H4Qd47pl0Wwrf6BTqx69FfGZhGFzEG3P";

        String forObject = restTemplate.getForObject("http://api.map.baidu.com/location/ip?ak=" + ak, String.class);

        return Result.response(ResultEnum.SUCCESS).setData(forObject);
    }

    @GetMapping("hitch")
    public Result SelectHitchByMap(@RequestParam("map")String map){
        //将此城市的顺风车推荐给用户
        List<SiteCar> cars = siteCarMapper.selectInfo(map);
        if (cars !=null){
            return Result.response(ResultEnum.SUCCESS).setData(cars);
        }else {
            return Result.response(ResultEnum.SUCCESS).setData(cars);
        }
    }

}
